package com.cs.framework.ui.builder.xml;

import com.cs.framework.common.util.CommonUtils;
import com.cs.framework.common.util.StringUtils;
import com.cs.framework.ui.builder.xml.model.PanelInfoForXml;
import com.cs.framework.ui.model.FieldInfo;
import com.cs.framework.ui.model.UIInfo;
import com.cs.framework.ui.util.UIConstant;

/**
 * 构建面板
 * 
 * @author hedongzhou
 * 
 */
public class PanelBuilder extends AbstractXmlUIBuilder {

	/**
	 * 构建面板
	 * 
	 * @param panelId
	 *            面板ID
	 * @param superPanelId
	 *            父面板ID
	 * @return
	 */
	public UIInfo build(String panelId, String superPanelId) {
		PanelInfoForXml panel = (PanelInfoForXml) build(panelId, UIConstant.PANEL_XML_PATH, PanelInfoForXml.class);

		if (CommonUtils.isNotEmpty(panel.getSubFieldList())) {
			String tempClassName = null;
			String className = panel.getFieldClassName();

			for (FieldInfo field : panel.getSubFieldList()) {
				if (StringUtils.isNotBlank(className)) {
					field.setClassName(className);
				} else if (StringUtils.isBlank(tempClassName)) {
					tempClassName = field.getClassName();
				}
			}

			if (StringUtils.isBlank(className) && StringUtils.isNotBlank(tempClassName)) {
				panel.setFieldClassName(tempClassName);
			}
		}

		return panel;
	}

}
